package com.hwadee.controller;

import com.hwadee.pojo.Doctor;
import com.hwadee.service.DoctorService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/doctor")
public class DoctorController {
    @Resource
    private DoctorService doctorService;
    //获取所有医生列表
    @GetMapping("/list")
    public List<Doctor> getAllDoctors() {
        return doctorService.getAllDoctors();
    }

    @GetMapping("/{id}")
    public Map<String, Object> getDoctorDetail(@PathVariable Integer id) {
        // 获取医生基本信息
        Doctor doctor = doctorService.getDoctorById(id);
        // 获取该医生绑定的所有老人姓名
        List<String> elderNames = doctorService.getBoundElderNames(id);
        // 将医生信息和老人姓名列表封装为 Map 返回
        Map<String, Object> result = new HashMap<>();
        result.put("doctor", doctor);
        result.put("elderNames", elderNames);
        return result;
    }

}
